package com.haiheng.module_main.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.haiheng.library_base.adapter.BaseAdapter
import com.haiheng.module_main.R
import com.haiheng.library_base.db.BookInfoBean
import com.haiheng.module_main.databinding.ItemBookReShellvingBinding

/**
 *
 * @Des:
 * @Author: hwz
 * @Date:2022/8/9 0009
 * @Version: 1.0
 */
class BookReShelvingAdapter : BaseAdapter<BookInfoBean>() {
    override fun onCreateViewBinding(viewType: Int): (LayoutInflater, ViewGroup, Boolean) -> ViewBinding {
        return ItemBookReShellvingBinding::inflate
    }

    override fun onItemView(holder: ViewBindHolder, position: Int, item: BookInfoBean) {
        val binding = holder.binding as ItemBookReShellvingBinding
        binding.tvBookSn.setText("条码：${item.barCode}")
        binding.tvBookName.setText("名称：${item.bookTitle}")

        binding.tvLocation.setText("位置：${item.currentContainerSub?.name?.toString()}第${item.currentPlaceIndex}本")
        //正确在架 1 错架 2  3 不在架
        val status = when (item.bookOnShelfStatus) {
            1 -> {
                binding.tvFixLoction.visibility = View.GONE
                "正确在架"
            }
            2 -> {
                binding.tvFixLoction.visibility = View.VISIBLE
                binding.tvFixLoction.setText("应在位置：${item.fixedContainerSub?.name?.toString()}")
                "错架"
            }
            3 ->{
                binding.tvFixLoction.visibility = View.GONE
                "不在架"
            }
            else -> {
                binding.tvFixLoction.visibility = View.GONE
                ""
            }
        }
       binding.tvStatus.text = "状态：$status"
       var context = holder.itemView.context
       var seshelfStatus =  when(item.customReshelfStatus){
            1 -> {
                holder.itemView.setBackgroundColor(context.getColor(R.color.color_5deb7b))
                "正确在架"
            }
            2 ->{
                holder.itemView.setBackgroundColor(context.getColor(R.color.color_ff7777))
                binding.tvFixLoction.visibility = View.VISIBLE
                binding.tvFixLoction.setText("应在位置：${item.fixedContainerSub?.name?.toString()}")
                "错架"
            }
            else ->{
                holder.itemView.setBackgroundColor(context.getColor(R.color.color_F7FAFC))
                ""
            }
        }
        if (seshelfStatus.isNotBlank()){
            binding.tvStatus.text = "状态：$seshelfStatus"
        }
        binding.tvAlarmed.visibility = if (item.isAlarmed) View.VISIBLE else View.GONE
        binding.tvRetirment.visibility = if (item.isRetirment) View.VISIBLE else View.GONE
        if (item.currentContainerSub == null || item.currentContainerSub?.name.isNullOrBlank()){
            binding.tvNotShelf.visibility = View.VISIBLE
        }else{
            binding.tvNotShelf.visibility = View.GONE
        }

    }
}